package ai.people.netmon.warning.grpc.client;

import ai.people.core.grpc.lib.key.account.KeyAccount;
import ai.people.core.grpc.lib.key.account.KeyAccountRpcServiceGrpc;
import ai.people.netmon.framework.exception.enums.CommonEnum;
import ai.people.netmon.framework.utils.AssertUtils;
import com.google.protobuf.BoolValue;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Component;

/**
 * @author yuanqinglong
 * @date 2022/8/11 19:37
 */
@Component
public class WarningAccountPushGrpcClient {

    @GrpcClient(value = "NM-SERVICE-ARCHIVES")
    private KeyAccountRpcServiceGrpc.KeyAccountRpcServiceBlockingStub keyAccountRpcServiceBlockingStub;

    /**
     * save2图
     * <pre>
     * 保存图服务
     * </pre>
     *
     * @param request 请求
     */
    public void save2Graph(KeyAccount request) {
        BoolValue boolValue = keyAccountRpcServiceBlockingStub.save2Graph(request);
        boolean value = boolValue.getValue();
        AssertUtils.isTrue(value, CommonEnum.FAIL);
    }


    /**
     * 删除图
     *
     * @param keyAccount 关键客户
     */
    public void deleteGraph(KeyAccount keyAccount){
        BoolValue boolValue = keyAccountRpcServiceBlockingStub.delGraph(keyAccount);
        boolean value = boolValue.getValue();
        AssertUtils.isTrue(value, CommonEnum.FAIL);
    }
}
